package com.xsmart.oa.api;

import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.oa.services.UserFavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户收藏
 *
 * @author guojd
 */
@RestController
@RequestMapping("/api")
public class UserFavoritesController {
    @Autowired
    UserFavoritesService userFavoritesService;

    /**
     * 用户收藏商品
     *
     * @param requestBean 请求对象
     *                    uid：用户id
     *                    pid：商品id
     * @return 是否成功
     */
    @PostMapping(value = "/v1/UserFavoritesService/addGoodsUserFavorites")
    public ResponseBean addGoodsUserFavorites(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userFavoritesService.addGoodsUserFavorites(requestBean);
    }

    /**
     * 查询用户收藏商品
     *
     * @param requestBean 请求对象
     *                    uid：用户id
     *                    pid：商品id
     * @return 是否成功
     */
    @PostMapping(value = "/v1/UserFavoritesService/queryGoodsUserFavorites")
    public ResponseBean queryGoodsUserFavorites(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userFavoritesService.queryGoodsUserFavorites(requestBean);
    }

    /**
     * 用户取消收藏
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/UserFavoritesService/removeGoodsUserFavorites")
    public ResponseBean removeGoodsUserFavorites(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userFavoritesService.removeGoodsUserFavorites(requestBean);
    }

    /**
     * 从商品详情页面中取消收藏
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value ="/v1/UserFavoritesService/deleteGoodsUserFavorites")
    public ResponseBean deleteGoodsUserFavorites(@ModelAttribute RequestBean requestBean,HttpServletRequest request){
        return userFavoritesService.deleteGoodsUserFavorites(requestBean);
    }

}
